home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / xlisp.lbr / XLBIND.CQ / xlbind.c
Encoding:
C/C++ Source or Header  |  1985-06-03  |  1.8 KB  |  77 lines

  1.                   /* xlbind - xlisp symbol binding routines */
  2.  
  3. #ifdef CI_86
  4. #include "a:stdio.h"
  5. #include "xlisp.h"
  6. #endif
  7.  
  8. #ifdef AZTEC
  9. #include "a:stdio.h"
  10. #include "xlisp.h"
  11. #endif
  12.  
  13. #ifdef unix
  14. #include <stdio.h>
  15. #include <xlisp.h>
  16. #endif
  17.  
  18.  
  19.                              /* global variables */
  20.  
  21. struct node *xlenv;
  22.  
  23.  
  24.             /********************************************************
  25.             *  xlunbind - unbind symbols bound in this environment  *
  26.             ********************************************************/
  27.  
  28. xlunbind(env)
  29.   struct node *env;
  30. {
  31.     struct node *bnd;
  32.  
  33.     for (; xlenv != env; xlenv = xlenv->n_listnext)
  34.     {
  35.         bnd = xlenv->n_listvalue;
  36.         bnd->n_bndsym->n_symvalue = bnd->n_bndvalue;
  37.     }
  38. }
  39.  
  40.  
  41.                      /**************************************
  42.                      *  xlbind - bind a symbol to a value  *
  43.                      **************************************/
  44.  
  45. xlbind(sym,val)
  46.   struct node *sym,*val;
  47. {
  48.     struct node *lptr,*bptr;
  49.  
  50.     lptr = newnode(LIST);              /* Create new environment list entry */
  51.     lptr->n_listnext = xlenv;
  52.     xlenv = lptr;
  53.  
  54.     lptr->n_listvalue = bptr = newnode(LIST);    /* New variable binding */
  55.     bptr->n_bndsym = sym;
  56.     bptr->n_bndvalue = val;
  57. }
  58.  
  59.  
  60.             /*******************************************************
  61.             *  xlfixbindings - make a new set of bindings visible  *
  62.             *******************************************************/
  63.  
  64. xlfixbindings(env)
  65.   struct node *env;
  66. {
  67.     struct node *eptr,*bnd,*sym,*oldvalue;
  68.  
  69.     for (eptr = xlenv; eptr != env; eptr = eptr->n_listnext) {
  70.         bnd = eptr->n_listvalue;
  71.         sym = bnd->n_bndsym;
  72.         oldvalue = sym->n_symvalue;
  73.         sym->n_symvalue = bnd->n_bndvalue;
  74.         bnd->n_bndvalue = oldvalue;
  75.     }
  76. }
  77.